#!/bin/bash
 E='echo -e';e='echo -en';trap "R;exit" 2
 ESC=$( $e "\e")
 TPUT(){ $e "\e[${1};${2}H" ;}
 CLEAR(){ $e "\ec";}
# 25 возможно это 
 CIVIS(){ $e "\e[?25l";}
# это цвет текста списка перед курсором при значении 0 в переменной  UNMARK(){ $e "\e[0m";}
 MARK(){ $e "\e[45m";}
# 0 это цвет заднего фона списка
 UNMARK(){ $e "\e[0m";}
# ~~~~~~~~ Эти строки задают цвет фона ~~~~~~~~
 R(){ CLEAR ;stty sane;CLEAR;};
#R(){ CLEAR ;stty sane;$e "\ec\e[37;44m\e[J";};
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 HEAD(){ for (( a=2; a<=37; a++ ))
  do
   TPUT $a 1
 $E "\033[32m\xE2\x94\x82                                                             \xE2\x94\x82\033[0m";
  done
 TPUT 3 4
 $E "\033[1;36mСправочник cryptsetup\033[0m";
 TPUT 35 3
 $E "\033[32mUp \xE2\x86\x91 \xE2\x86\x93 Down Select Enter\033[0m";
 MARK;TPUT 1 1
 $E "\033[32m+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\033[0m";UNMARK;}
  i=0; CLEAR; CIVIS;NULL=/dev/null
 FOOT(){ MARK;TPUT 38 1
 $E "\033[32m+~~~| Grannik | 2021.11.03 |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+\033[0m";UNMARK;}
# это управляет кнопками ввер/хвниз
 i=0; CLEAR; CIVIS;NULL=/dev/null
#
 ARROW(){ IFS= read -s -n1 key 2>/dev/null >&2
           if [[ $key = $ESC ]];then 
              read -s -n1 key 2>/dev/null >&2;
              if [[ $key = \[ ]]; then
                 read -s -n1 key 2>/dev/null >&2;
                 if [[ $key = A ]]; then echo up;fi
                 if [[ $key = B ]];then echo dn;fi
              fi
           fi
           if [[ "$key" == "$($e \\x0A)" ]];then echo enter;fi;}
 M0(){ TPUT  5 3; $e " \033[32m \033[0m";}
 M1(){ TPUT  6 3; $e " \033[32m \033[0m";}
 M2(){ TPUT  7 3; $e " \033[32m \033[0m";}
 M3(){ TPUT  8 3; $e " \033[32m \033[0m";}
 M4(){ TPUT  9 3; $e " \033[32m \033[0m";}
 M5(){ TPUT 10 3; $e " \033[32m \033[0m";}
 M6(){ TPUT 11 3; $e " \033[32m \033[0m";}
 M7(){ TPUT 12 3; $e " \033[32m \033[0m";}
 M8(){ TPUT 13 3; $e " \033[32m \033[0m";}
 M9(){ TPUT 14 3; $e " \033[32m \033[0m";}
M10(){ TPUT 15 3; $e " \033[32m \033[0m";}
M11(){ TPUT 16 3; $e " \033[32m \033[0m";}
M12(){ TPUT 17 3; $e " \033[32m \033[0m";}
M13(){ TPUT 18 3; $e " \033[32m \033[0m";}
M14(){ TPUT 19 3; $e " \033[32m \033[0m";}
M15(){ TPUT 20 3; $e " \033[32m \033[0m";}
M16(){ TPUT 21 3; $e " \033[32m \033[0m";}
M17(){ TPUT 22 3; $e " \033[32m \033[0m";}
M18(){ TPUT 23 3; $e " \033[32m \033[0m";}
M19(){ TPUT 24 3; $e " \033[32m \033[0m";}
M20(){ TPUT 25 3; $e " \033[32m \033[0m";}
M21(){ TPUT 26 3; $e " \033[32m \033[0m";}
M22(){ TPUT 27 3; $e " \033[32m \033[0m";}
M23(){ TPUT 28 3; $e " \033[32m \033[0m";}
M24(){ TPUT 29 3; $e " \033[32m \033[0m";}
M25(){ TPUT 30 3; $e " \033[32m \033[0m";}
M26(){ TPUT 31 3; $e " \033[32m \033[0m";}
M27(){ TPUT 32 3; $e " \033[32m \033[0m";}
M28(){ TPUT 33 3; $e " \033[32m \033[0m";}
M29(){ TPUT 34 3; $e " \033[32m \033[0m";}
#
M30(){ TPUT 36 3; $e " EXIT";}
LM=30
   MENU(){ for each in $(seq 0 $LM);do M${each};done;}
    POS(){ if [[ $cur == up ]];then ((i--));fi
           if [[ $cur == dn ]];then ((i++));fi
           if [[ $i -lt 0   ]];then i=$LM;fi
           if [[ $i -gt $LM ]];then i=0;fi;}
REFRESH(){ after=$((i+1)); before=$((i-1))
           if [[ $before -lt 0  ]];then before=$LM;fi
           if [[ $after -gt $LM ]];then after=0;fi
           if [[ $j -lt $i      ]];then UNMARK;M$before;else UNMARK;M$after;fi
           if [[ $after -eq 0 ]] || [ $before -eq $LM ];then
           UNMARK; M$before; M$after;fi;j=$i;UNMARK;M$before;M$after;}
   INIT(){ R;HEAD;FOOT;MENU;}
     SC(){ REFRESH;MARK;$S;$b;cur=`ARROW`;}
# Функция возвращения в меню
     ES(){ MARK;$e " ENTER = main menu ";$b;read;INIT;};INIT
  while [[ "$O" != " " ]]; do case $i in
  0) S=M0;SC;if [[ $cur == enter ]];then R;echo "
 
";ES;fi;;
  1) S=M1;SC;if [[ $cur == enter ]];then R;echo "
 
";ES;fi;;
  2) S=M2;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
  3) S=M3;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
  4) S=M4;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
  5) S=M5;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
  6) S=M6;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
  7) S=M7;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
  8) S=M8;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
  9) S=M9;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;

 10) S=M10;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 11) S=M11;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 12) S=M12;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 13) S=M13;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 14) S=M14;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 15) S=M15;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 16) S=M16;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 17) S=M17;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 18) S=M18;SC;if [[ $cur == enter ]];then R;echo -e "
 
";ES;fi;;
 19) S=M19;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 20) S=M20;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 21) S=M21;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 22) S=M22;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 23) S=M23;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 24) S=M24;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 25) S=M25;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 26) S=M26;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 27) S=M27;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 28) S=M28;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
 29) S=M29;SC;if [[ $cur == enter ]];then R;echo " ";ES;fi;;
#
 30) S=M30;SC;if [[ $cur == enter ]];then R;clear;ls -l;exit 0;fi;;
 esac;POS;done
